package main

import (
	"context"
	"flag"
	"log"
	"time"
	"tym/codec/client"
	"tym/codec/internal/service"
)

var (
	port string
)

func main() {
	flag.StringVar(&port, "port", "8002", "config path, eg: -conf config.yaml")
	flag.Parse()

	client, _ := client.Dial("tcp", ":"+port)
	defer client.Close()

	for i := 0; i < 5; i++ {

		args := &service.Args{Num1: i, Num2: i * i}
		var reply int
		ctx, _ := context.WithTimeout(context.Background(), time.Second)
		if err := client.Call(ctx, "Foo.Sum", args, &reply); err != nil {
			log.Fatal("call Foo.Sum error:", err)
		}
		log.Println("reply:", reply)
	}
}
